package com.hqd.jjvm.classformat.constantpool;

import com.hqd.jjvm.classformat.ClassFile;
import com.hqd.jjvm.rtda.heap.ref.JClassRef;
import com.hqd.jjvm.util.HexStrTransformUtil;
import lombok.Getter;

import java.util.List;

@Getter
public class ConstantClassInfo extends ConstantPool {
	private Integer classNameIndex;

	public ConstantClassInfo(ConstantInfoType tag, ClassFile classFile) {
		super(tag, classFile);
		this.classNameIndex = HexStrTransformUtil.parseHexToInt(classFile.readU2());
		checkPoolIndex(classNameIndex);
	}


	@Override
	public JClassRef getVal() {
		List<ConstantPool> constantPools = classFile.getConstantPools();
		JClassRef jClassRef = new JClassRef();
		jClassRef.setClassName(constantPools.get(classNameIndex).getVal().toString());
		return jClassRef;
	}
}
